package com.wangsh.splider.system.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangsh.splider.common.pojo.ApiResponse;
import com.wangsh.splider.common.pojo.ApiResponseEnum;
import com.wangsh.splider.common.pojo.JSONEnum;
import com.wangsh.splider.common.service.BaseServiceImpl;
import com.wangsh.splider.common.util.ConstatFinalUtil;
import com.wangsh.splider.common.util.PageInfoUtil;
import com.wangsh.splider.orders.service.IOrdersOperService;
import com.wangsh.splider.system.dao.IASysClientDao;
import com.wangsh.splider.system.dao.IASysCountryDao;
import com.wangsh.splider.system.dao.IASysFileDao;
import com.wangsh.splider.system.dao.IASysIpDao;
import com.wangsh.splider.system.dao.IASysMailAccountDao;
import com.wangsh.splider.system.dao.IASysProDao;
import com.wangsh.splider.system.dao.IASysProxyDao;
import com.wangsh.splider.system.dao.IASysShortUrlDao;
import com.wangsh.splider.system.dao.IASysWebSiteDao;
import com.wangsh.splider.system.dao.IASysWebUrlDao;
import com.wangsh.splider.system.pojo.ASysClient;
import com.wangsh.splider.system.pojo.ASysCountry;
import com.wangsh.splider.system.pojo.ASysFile;
import com.wangsh.splider.system.pojo.ASysFileEnum;
import com.wangsh.splider.system.pojo.ASysIp;
import com.wangsh.splider.system.pojo.ASysMailAccount;
import com.wangsh.splider.system.pojo.ASysPro;
import com.wangsh.splider.system.pojo.ASysProEnum;
import com.wangsh.splider.system.pojo.ASysProxy;
import com.wangsh.splider.system.pojo.ASysProxyEnum;
import com.wangsh.splider.system.pojo.ASysShortUrl;
import com.wangsh.splider.system.pojo.ASysWebSite;
import com.wangsh.splider.system.pojo.ASysWebUrl;
import com.wangsh.splider.system.pojo.ASysWebUrlEnum;
import com.wangsh.splider.system.service.ISystemOperService;
import com.wangsh.splider.system.service.ISystemDbService;
import com.wangsh.splider.task.service.ITaskOperService;

/**
 * 系统的Service
 *
 * @author TeaBig
 */
@Service("systemDbService")
public class SystemDbServiceImpl extends BaseServiceImpl implements ISystemDbService
{
	@Resource
	private IASysFileDao sysFileDao;
	@Resource
	private IASysProDao sysProDao;
	@Resource
	private IASysIpDao sysIpDao;
	@Resource
	private IASysCountryDao sysCountryDAO;
	@Resource
	private IASysProxyDao sysProxyDao;
	@Resource
	private IASysMailAccountDao  sysMailAccountDao;
	@Resource
	private IASysShortUrlDao sysShortUrlDao;
	@Resource
	private IASysClientDao sysClientDao;
	@Resource
	private IASysWebSiteDao sysWebSiteDao;

	@Resource
	private IOrdersOperService ordersOperService;
	@Resource
	private ISystemOperService systemOperService;
	@Resource
	private ITaskOperService taskOperService;

	/**
	 * 初始化操作
	 */
	@PostConstruct
	public ApiResponse<Object> reloadSystem()
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 查询所有启用的共享变量,系统配置 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("status", ASysProEnum.STATUS_ENABLE.getStatus());
		ApiResponse<ASysPro> response = this.findCondListSysProService(null, condMap);
		List<ASysPro> sysProList = response.getDataListJava();
		/* 循环放到Map中 */
		for (Iterator iterator = sysProList.iterator(); iterator.hasNext();)
		{
			ASysPro sysPro = (ASysPro) iterator.next();
			ConstatFinalUtil.SYS_PRO_MAP.put(sysPro.getEngName(), sysPro);
		}
		ConstatFinalUtil.SYS_LOGGER.info("==初始化完成==变量:{}", ConstatFinalUtil.SYS_PRO_MAP);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> saveOneSysFileService(ASysFile sysFile)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		sysFile.setCreateTime(new Date());
		sysFile.setUpdateTime(new Date());
		int res = this.sysFileDao.save(sysFile);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysFile.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysFile);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	public ApiResponse<Object> updateOneSysFileService(ASysFile sysFile)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		sysFile.setUpdateTime(new Date());
		int res = this.sysFileDao.update(sysFile);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysFile.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysFile);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneSysFileService(ASysFile sysFile, Map<String, Object> paramsMap) throws Exception
	{
		if (paramsMap.size() == 0)
		{
			return this.updateOneSysFileService(sysFile);
		}

		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		try
		{
			String fileName = paramsMap.get("fileName") + "";
			InputStream is = (InputStream) paramsMap.get("inputStream");
			String fileSize = paramsMap.get("fileSize") + "";

			/* 上传文件的相对路径 */
			String uploadFile = ConstatFinalUtil.CONFIG_JSON.getString("website.uploadFile");
			/* 存储的是网址的绝对路径 */
			String souPath = sysFile.getFilePath();
			/* 真实路径 */
			String truePath = ConstatFinalUtil.CONFIG_JSON.getString("website.truePath");
			String midPath = "sysFile";
			if (sysFile.getFileRelaType() == ASysFileEnum.FILERELATYPE_USERSCATE.getStatus())
			{
				/* 读取usersCate的系统变量 */
				ASysPro usersCateSys = (ASysPro) ConstatFinalUtil.SYS_PRO_MAP.get("uploadPath_cate");
				midPath = usersCateSys.getVals();
			}else if (sysFile.getFileRelaType() == ASysFileEnum.FILERELATYPE_EMAILS_PHONE.getStatus())
			{
				/* 读取usersCate的系统变量 */
				ASysPro usersCateSys = (ASysPro) ConstatFinalUtil.SYS_PRO_MAP.get("uploadPath_taskUsers");
				midPath = usersCateSys.getVals();
			} else if (sysFile.getFileRelaType() == ASysFileEnum.FILERELATYPE_FB_USERS.getStatus())
			{
				ASysPro usersCateSys = (ASysPro) ConstatFinalUtil.SYS_PRO_MAP.get("uploadPath_facebook_users");
				midPath = usersCateSys.getVals();
			}
			/*
			 * 网站的相对路径, 路径是写活的
			 * 网站的相对路径, * 路径是写活的
			 */
			String tarRelaPath = uploadFile + "/" + midPath + "/" + this.dateFormatUtil.dateStr(new Date()) + "/"
					+ UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."), fileName.length());
			File tarTrueFile = new File(truePath + tarRelaPath);

			/* 创建父目录 */
			if (!tarTrueFile.getParentFile().exists())
			{
				tarTrueFile.getParentFile().mkdirs();
			}
			sysFile.setName(fileName);
			sysFile.setFileSize(fileSize);
			sysFile.setFilePath(tarRelaPath);

			FileOutputStream fos = new FileOutputStream(tarTrueFile);
			/* 复制文件 */
			boolean flag = this.fileUtil.copyFile(is, fos);
			if (flag)
			{
				/* 对上传文件进行处理 */
				if (sysFile.getFileRelaType() == ASysFileEnum.FILERELATYPE_FB_USERS.getStatus())
				{
					FileInputStream fis = new FileInputStream(tarTrueFile);
					List<Map<String, Object>> dataList = this.poiUtil.readExcel(fis, "xlsx");
					/* facebook用户上传处理 */
					apiResponse = this.ordersOperService.batchOrdersUsersService(dataList);
					ConstatFinalUtil.SYS_LOGGER.info("批量导入订单用户信息:{}", apiResponse.toJSON().toJSONString());
				}else if (sysFile.getFileRelaType() == ASysFileEnum.FILERELATYPE_EMAILS_PHONE.getStatus())
				{
					/* 处理邮箱用户模板 */
					Map<String, Object> usersParamsMap = new HashMap<String, Object>();
					usersParamsMap.put("souFile", tarTrueFile);
					usersParamsMap.put("taskId", sysFile.getRelaId() + "");
					apiResponse = this.taskOperService.operUsersBatchService(usersParamsMap, "GBK");
				}else
				{
					apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
				}

				if (souPath != null && !"".equalsIgnoreCase(souPath))
				{
					/* 相对路径 */
					File souFile = new File(truePath + souPath);
					if (!souFile.delete())
					{
						ConstatFinalUtil.SYS_LOGGER.error("删除原始文件失败:原始文件路径:{}", souFile.getAbsolutePath());
					}
				}
			}

			/* 更新记录 */
			this.updateOneSysFileService(sysFile);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("上传头像失败了,id:{}", sysFile.getId(), e);
			throw e;
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneSysFileService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysFileDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysFile> findCondListSysFileService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysFile> apiResponse = new ApiResponse<ASysFile>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysFile> sysFileList = Collections.EMPTY_LIST;

		Map<String, List<ASysFile>> dataList = new HashMap<String, List<ASysFile>>();
		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			sysFileList = this.sysFileDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			sysFileList = this.sysFileDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), sysFileList);

		apiResponse.setDataListJava(sysFileList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysFile> findOneSysFileService(Map<String, Object> condMap)
	{
		ApiResponse<ASysFile> apiResponse = new ApiResponse<ASysFile>();

		Map<String, ASysFile> data = new HashMap<String, ASysFile>();
		ASysFile sysFile = this.sysFileDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), sysFile);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(sysFile);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/* 系统配置操作开始 */
	@Override
	public ApiResponse<Object> saveOneSysProService(ASysPro sysPro)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		sysPro.setCreateTime(new Date());
		sysPro.setUpdateTime(new Date());
		int res = this.sysProDao.save(sysPro);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysPro.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysPro);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneSysProService(ASysPro sysPro)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		int res = this.sysProDao.update(sysPro);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysPro.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysPro);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneSysProService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysProDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysPro> findCondListSysProService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysPro> apiResponse = new ApiResponse<ASysPro>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysPro> SysProList = Collections.EMPTY_LIST;

		Map<String, List<ASysPro>> dataList = new HashMap<String, List<ASysPro>>();
		try
		{

			/* 对关键字进行模糊匹配 */
			if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
			{
				condMap.put("keyword", "%" + condMap.get("keyword") + "%");
			}

			/* 设置分页相关信息 */
			if (pageInfoUtil != null)
			{
				/* 设置分页信息 */
				Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
				SysProList = this.sysProDao.findList(condMap);
				pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
				/* 向接口中放分页信息 */
				apiResponse.setPageInfoUtil(pageInfoUtil);
			} else
			{
				SysProList = this.sysProDao.findList(condMap);
			}
			/* 将结果放到JSON中 */
			dataList.put(ApiResponseEnum.NAME_LIST.getName(), SysProList);

			apiResponse.setDataListJava(SysProList);
			apiResponse.setDataList(dataList);
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("查询多条记录失败了", e);
			apiResponse.setCode(ApiResponseEnum.STATUS_SERVER_ERROR.getStatus());
			Map<String, String> infoMap = new HashMap<String, String>();
			/* 报错信息的占位符 */
			infoMap.put("errinfo", e.toString());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), infoMap);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysPro> findOneSysProService(Map<String, Object> condMap)
	{
		ApiResponse<ASysPro> apiResponse = new ApiResponse<ASysPro>();

		Map<String, ASysPro> data = new HashMap<String, ASysPro>();
		ASysPro SysPro = this.sysProDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), SysPro);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(SysPro);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	// Country开始
	@Override
	public ApiResponse<Object> saveOneCountryService(ASysCountry country)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		int res = this.sysCountryDAO.save(country);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), country.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), country);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneCountryService(ASysCountry country)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysCountryDAO.update(country);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), country.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), country);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneCountryService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysCountryDAO.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysCountry> findCondListCountryService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysCountry> apiResponse = new ApiResponse<ASysCountry>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysCountry> syscountryList = Collections.EMPTY_LIST;

		Map<String, List<ASysCountry>> dataList = new HashMap<String, List<ASysCountry>>();
		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			syscountryList = this.sysCountryDAO.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			syscountryList = this.sysCountryDAO.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), syscountryList);

		apiResponse.setDataListJava(syscountryList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysCountry> findOneCountryService(Map<String, Object> condMap)
	{
		ApiResponse<ASysCountry> apiResponse = new ApiResponse<ASysCountry>();

		Map<String, ASysCountry> data = new HashMap<String, ASysCountry>();
		ASysCountry country = this.sysCountryDAO.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), country);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(country);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	// ip
	@Override
	public ApiResponse<Object> saveOneSysIpService(ASysIp aSysIp)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String, Object> condMap = new HashMap<String, Object>();
		if (aSysIp.getIp() == null || "".equalsIgnoreCase(aSysIp.getIp()))
		{
			/* ip不能为空 */
			/* 记录已经存在 */
			apiResponse.setCode(ApiResponseEnum.INFO_ERROR_FORMAT.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
			return apiResponse;
		}
		/* 根据ip查询,ip永远不能为空 */
		condMap.clear();
		condMap.put("ip", aSysIp.getIp());
		ApiResponse<ASysIp> apiResponseRes = this.findOneSysIpService(condMap);
		ASysIp sysIpRes = apiResponseRes.getDataOneJava();
		if (sysIpRes != null)
		{
			/* 记录已经存在 */
			apiResponse.setCode(ApiResponseEnum.INFO_RECORD_EXISTS.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
			return apiResponse;
		}

		aSysIp.setCreateTime(new Date());
		aSysIp.setUpdateTime(new Date());
		
		int res = this.sysIpDao.save(aSysIp);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), aSysIp.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), aSysIp);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneSysIpService(ASysIp aSysIp)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysIpDao.update(aSysIp);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), aSysIp.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), aSysIp);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneSysIpService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysIpDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysIp> findCondListSysIpService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysIp> apiResponse = new ApiResponse<ASysIp>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysIp> sysIpList = Collections.EMPTY_LIST;

		Map<String, List<ASysIp>> dataList = new HashMap<String, List<ASysIp>>();
		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			sysIpList = this.sysIpDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			sysIpList = this.sysIpDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), sysIpList);

		apiResponse.setDataListJava(sysIpList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysIp> findOneSysIpService(Map<String, Object> condMap)
	{
		ApiResponse<ASysIp> apiResponse = new ApiResponse<ASysIp>();

		Map<String, ASysIp> data = new HashMap<String, ASysIp>();
		ASysIp aSysIp = this.sysIpDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), aSysIp);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(aSysIp);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	// == ip代理开始 ==
	@Override
	public ApiResponse<Object> saveOneSysProxyService(ASysProxy sysProxy)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String, Object> condMap = new HashMap<String, Object>();
		/* 根据ip查询,ip永远不能为空 */
		condMap.clear();
		condMap.put("ip", sysProxy.getIp());
		ApiResponse<ASysProxy> apiResponseRes = this.findOneSysProxyService(condMap);
		ASysProxy sysProxyRes = apiResponseRes.getDataOneJava();
		if (sysProxyRes != null)
		{
			/* 记录已经存在 */
			apiResponse.setCode(ApiResponseEnum.INFO_RECORD_EXISTS.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
			return apiResponse;
		}
		int res = this.sysProxyDao.save(sysProxy);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysProxy.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysProxy);
			apiResponse.setDataOne(dataMap);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneSysProxyService(ASysProxy sysProxy)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		if (sysProxy.getFailedNum() >= Integer
				.valueOf(ConstatFinalUtil.CONFIG_JSON.getString("system.proxy.failedCount")))
		{
			sysProxy.setStatus(ASysProxyEnum.STATUS_INVALID.getStatus());
		}
		int res = this.sysProxyDao.update(sysProxy);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysProxy.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysProxy);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneSysProxyService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysProxyDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysProxy> findCondListSysProxyService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysProxy> apiResponse = new ApiResponse<ASysProxy>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysProxy> demoDynastyList = Collections.EMPTY_LIST;

		Map<String, List<ASysProxy>> dataList = new HashMap<String, List<ASysProxy>>();
		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoDynastyList = this.sysProxyDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			demoDynastyList = this.sysProxyDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoDynastyList);

		apiResponse.setDataListJava(demoDynastyList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysProxy> findOneSysProxyService(Map<String, Object> condMap)
	{
		ApiResponse<ASysProxy> apiResponse = new ApiResponse<ASysProxy>();

		Map<String, ASysProxy> data = new HashMap<String, ASysProxy>();
		ASysProxy sysProxy = this.sysProxyDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), sysProxy);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(sysProxy);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	// == ip代理结束 ==

	// 邮箱账号开始
	@Override
	public ApiResponse<Object> saveOneMailAccountService(ASysMailAccount account)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysMailAccountDao.save(account);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), account.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), account);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneMailAccountService(ASysMailAccount account)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysMailAccountDao.update(account);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), account.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), account);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneMailAccountService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysMailAccountDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysMailAccount> findCondListMailAccountService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysMailAccount> apiResponse = new ApiResponse<ASysMailAccount>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysMailAccount> sysaccountList = Collections.EMPTY_LIST;

		Map<String, List<ASysMailAccount>> dataList = new HashMap<String, List<ASysMailAccount>>();
		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			sysaccountList = this.sysMailAccountDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			sysaccountList = this.sysMailAccountDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), sysaccountList);

		apiResponse.setDataListJava(sysaccountList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysMailAccount> findOneMailAccountService(Map<String, Object> condMap)
	{
		ApiResponse<ASysMailAccount> apiResponse = new ApiResponse<ASysMailAccount>();

		Map<String, ASysMailAccount> data = new HashMap<String, ASysMailAccount>();
		ASysMailAccount account = this.sysMailAccountDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), account);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(account);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	// -- 客户端列表 --
	@Override
	public ApiResponse<Object> saveOneClientService(ASysClient client)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String, Object> condMap = new HashMap<String, Object>();
		client.setTotalNum(client.getSuccedNum() + client.getFailedNum());
		client.setTodayTotalNum(client.getTodaySuccedNum() + client.getTodayFailedNum());

		/* 根据ip查询,ip永远不能为空 */
		condMap.clear();
		condMap.put("ipId", client.getIpId());
		ApiResponse<ASysIp> apiResponseRes = this.findOneSysIpService(condMap);
		ASysIp sysIpRes = apiResponseRes.getDataOneJava();
		if (sysIpRes != null)
		{
			/* 记录已经存在 */
			apiResponse.setCode(ApiResponseEnum.INFO_RECORD_EXISTS.getStatus());
			apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
			return apiResponse;
		}

		int res = this.sysClientDao.save(client);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), client.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), client);
			apiResponse.setDataOne(dataMap);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneClientService(ASysClient client)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
//				client.setAge(Client.getEdYear() - Client.getStYear());
		client.setTotalNum(client.getSuccedNum() + client.getFailedNum());
		client.setTodayTotalNum(client.getTodaySuccedNum() + client.getTodayFailedNum());
		int res = this.sysClientDao.update(client);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), client.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), client);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneClientService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysClientDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysClient> findCondListClientService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysClient> apiResponse = new ApiResponse<ASysClient>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysClient> aSysClientList = Collections.EMPTY_LIST;

		Map<String, List<ASysClient>> dataList = new HashMap<String, List<ASysClient>>();
		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			aSysClientList = this.sysClientDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			aSysClientList = this.sysClientDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), aSysClientList);

		apiResponse.setDataListJava(aSysClientList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysClient> findOneClientService(Map<String, Object> condMap)
	{
		ApiResponse<ASysClient> apiResponse = new ApiResponse<ASysClient>();

		Map<String, ASysClient> data = new HashMap<String, ASysClient>();
		ASysClient aSysClient = this.sysClientDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), aSysClient);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(aSysClient);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysClient> findOneClientByMinAttackService(Map<String, Object> condMap)
	{
		ApiResponse<ASysClient> apiResponse = new ApiResponse<ASysClient>();

		Map<String, ASysClient> data = new HashMap<String, ASysClient>();
		ASysClient aSysClient = this.sysClientDao.findOneByMinAttack(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), aSysClient);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(aSysClient);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}
	// -- 客户端列表结束 --

	// -- 网站列表开始--
	@Override
	public ApiResponse<Object> saveOneWebSiteService(ASysWebSite webSite)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
//						dynasty.setAge(dynasty.getEdYear() - dynasty.getStYear());
//						client.setTotalNum(client.getSuccedNum()+client.getFailedNum());
//						client.setTodayTotalNum(client.getTodaySuccedNum()+client.getTodayFailedNum());
		int res = this.sysWebSiteDao.save(webSite);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), webSite.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), webSite);
			apiResponse.setDataOne(dataMap);
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneWebSiteService(ASysWebSite webSite)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
//						client.setAge(Client.getEdYear() - Client.getStYear());
		int res = this.sysWebSiteDao.update(webSite);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), webSite.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), webSite);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneWebSiteService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysWebSiteDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysWebSite> findCondListWebSiteService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysWebSite> apiResponse = new ApiResponse<ASysWebSite>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysWebSite> aSysWebSiteList = Collections.EMPTY_LIST;

		Map<String, List<ASysWebSite>> dataList = new HashMap<String, List<ASysWebSite>>();

		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			aSysWebSiteList = this.sysWebSiteDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			aSysWebSiteList = this.sysWebSiteDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), aSysWebSiteList);

		apiResponse.setDataListJava(aSysWebSiteList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysWebSite> findOneWebSiteService(Map<String, Object> condMap)
	{
		ApiResponse<ASysWebSite> apiResponse = new ApiResponse<ASysWebSite>();

		Map<String, ASysWebSite> data = new HashMap<String, ASysWebSite>();
		ASysWebSite aSysWebSite = this.sysWebSiteDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), aSysWebSite);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(aSysWebSite);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}
	// -- 网站列表结束 --

	/**
	 * 网站Url的Service实现类
	 *
	 * @author Songhy
	 */
	@Resource
	private IASysWebUrlDao sysWebUrlDao;

	@Override
	public ApiResponse<Object> saveOneWebUrlService(ASysWebUrl sysWebUrl)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		// 随机获取50条记录
		JSONArray operOrderRead = systemOperService.operOrderRead(condMap, sysWebUrl);
		sysWebUrl.setHeader(operOrderRead.toJSONString());

		int res = this.sysWebUrlDao.save(sysWebUrl);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysWebUrl.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysWebUrl);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneWebUrlService(ASysWebUrl sysWebUrl)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 如果成功次数+失败次数,大于总次数,直接设置为禁用 */
		if (sysWebUrl.getTotalCount() <= sysWebUrl.getSuccedCount() + sysWebUrl.getFailedCount())
		{
			sysWebUrl.setStatus(ASysWebUrlEnum.STATUS_DISABLE.getStatus());
		}

		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.clear();
		// 随机获取50条记录
		JSONArray operOrderRead = systemOperService.operOrderRead(condMap, sysWebUrl);
		sysWebUrl.setHeader(operOrderRead.toJSONString());

		sysWebUrl.setUpdateTime(new Date());
		int res = this.sysWebUrlDao.update(sysWebUrl);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), sysWebUrl.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), sysWebUrl);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneWebUrlService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysWebUrlDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysWebUrl> findCondListWebUrlService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysWebUrl> apiResponse = new ApiResponse<ASysWebUrl>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysWebUrl> sysWebUrlList = Collections.EMPTY_LIST;

		Map<String, List<ASysWebUrl>> dataList = new HashMap<String, List<ASysWebUrl>>();
		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			sysWebUrlList = this.sysWebUrlDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			sysWebUrlList = this.sysWebUrlDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), sysWebUrlList);

		apiResponse.setDataListJava(sysWebUrlList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
					Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysWebUrl> findOneWebUrlService(Map<String, Object> condMap)
	{
		ApiResponse<ASysWebUrl> apiResponse = new ApiResponse<ASysWebUrl>();

		Map<String, ASysWebUrl> data = new HashMap<String, ASysWebUrl>();
		ASysWebUrl sysWebUrl = this.sysWebUrlDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), sysWebUrl);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(sysWebUrl);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""),
				Collections.EMPTY_MAP);
		return apiResponse;
	}

	// 短连接开始
	@Override
	public ApiResponse<Object> saveOneShortUrlService(ASysShortUrl shortUrl)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		int res = this.sysShortUrlDao.save(shortUrl);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), shortUrl.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), shortUrl);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneShortUrlService(ASysShortUrl shortUrl)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		int res = this.sysShortUrlDao.update(shortUrl);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), shortUrl.getId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), shortUrl);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneShortUrlService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.sysShortUrlDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysShortUrl> findCondListShortUrlService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ASysShortUrl> apiResponse = new ApiResponse<ASysShortUrl>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ASysShortUrl> sysshortUrlList = Collections.EMPTY_LIST;

		Map<String, List<ASysShortUrl>> dataList = new HashMap<String, List<ASysShortUrl>>();

		/* 对关键字进行模糊匹配 */
		if (condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + ""))
		{
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		/* 设置分页相关信息 */
		if (pageInfoUtil != null)
		{
			/* 设置分页信息 */
			Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			sysshortUrlList = this.sysShortUrlDao.findList(condMap);
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
			/* 向接口中放分页信息 */
			apiResponse.setPageInfoUtil(pageInfoUtil);
		} else
		{
			sysshortUrlList = this.sysShortUrlDao.findList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), sysshortUrlList);

		apiResponse.setDataListJava(sysshortUrlList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ASysShortUrl> findOneShortUrlService(Map<String, Object> condMap)
	{
		ApiResponse<ASysShortUrl> apiResponse = new ApiResponse<ASysShortUrl>();

		Map<String, ASysShortUrl> data = new HashMap<String, ASysShortUrl>();
		ASysShortUrl shortUrl = this.sysShortUrlDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), shortUrl);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(shortUrl);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
}
